// 七牛云接口
import { Controller, Get, Post, ApiInfo, JwtUnless } from '../../../../libs/koa-action-decorator/index';
import { qiniuConfig } from '../../../../config/index';
import qiniu from 'qiniu';
import { ErrorModel, SuccessModel } from '../../../../utils/respond/ResModel'
export default @ApiInfo({ name: '七牛接口', catalogue: '工具模块' })
@Controller('/api/common/qiniu')
class qiniuControllers {
    @Get('/uptoken')
    @JwtUnless
    @ApiInfo('获取七牛上传token')
    async uptoken(ctx, next) {
        let filename = ctx.getQueryString('filename')
        let mac = new qiniu.auth.digest.Mac(qiniuConfig.accessKey, qiniuConfig.secretKey)
        let options = {
            scope: filename !== '' ? `${qiniuConfig.bucket}:${filename}` : qiniuConfig.bucket
        }
        let putPolicy = new qiniu.rs.PutPolicy(options)
        let uploadToken = putPolicy.uploadToken(mac)
        ctx.body = new SuccessModel({ uploadToken })
    }
}